package miao.byusi.bkata.logs

/**
 * 文本样式类
 */
data class Style(
    val color: Color? = null,
    val bgColor: Color? = null,
    val bold: Boolean = false,
    val italic: Boolean = false,
    val underline: Boolean = false
) {
    fun toAnsiCodes(): String {
        val codes = mutableListOf<String>()
        
        color?.let { codes.add(it.foregroundCode) }
        bgColor?.let { codes.add(it.backgroundCode) }
        if (bold) codes.add("1")
        if (italic) codes.add("3")
        if (underline) codes.add("4")
        
        return codes.joinToString(";")
    }
}

/**
 * ANSI 颜色枚举
 */
enum class Color(val foregroundCode: String, val backgroundCode: String) {
    BLACK("30", "40"),
    RED("31", "41"),
    GREEN("32", "42"),
    YELLOW("33", "43"),
    BLUE("34", "44"),
    MAGENTA("35", "45"),
    CYAN("36", "46"),
    WHITE("37", "47"),
    BRIGHT_BLACK("90", "100"),
    BRIGHT_RED("91", "101"),
    BRIGHT_GREEN("92", "102"),
    BRIGHT_YELLOW("93", "103"),
    BRIGHT_BLUE("94", "104"),
    BRIGHT_MAGENTA("95", "105"),
    BRIGHT_CYAN("96", "106"),
    BRIGHT_WHITE("97", "107");
    
    companion object {
        fun fromString(name: String): Color? {
            return values().find { it.name.equals(name, ignoreCase = true) }
        }
    }
}